package baltazar;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

public class TopMenu extends JPanel {

	private ImageIcon redIcon = new ImageIcon("./images/red.png");
	private ImageIcon grayIcon = new ImageIcon("./images/gray.png");
	private ImageIcon logoutIcon = new ImageIcon("./images/logout.png");
	private JButton record = new JButton("   Ewidencja", redIcon);
	private JButton employees = new JButton("   Pracownicy", grayIcon);
	private JButton clients = new JButton("   Klienci", grayIcon);
	private JButton report = new JButton("   Raport", grayIcon);
	private JButton logout = new JButton("wyloguj ", logoutIcon);
	private ContentRecord contentRecord = new ContentRecord();
	private ContentEmployees contentEmployees = new ContentEmployees();
	private ContentClients contentClients = new ContentClients();
	private ContentReport contentReport = new ContentReport();
	private BaseContent baseContent;

	public TopMenu(BaseContent cnt) {
		setBackground(new Color(250, 250, 198));
		UIManager.put("Button.select", new Color(250, 250, 120));
		setLayout(new GridLayout(1, 5));
		baseContent = cnt;
		setColorButton(record);

		record.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setColorButton((JButton) e.getSource());
				contentRecord = new ContentRecord();
				baseContent.setContent(contentRecord);
			}
		});
		record.setBackground(new Color(250, 250, 198));
		record.setBorderPainted(false);
		record.setFocusable(false);
		add(record);

		employees.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				setColorButton((JButton) e.getSource());
				contentEmployees = new ContentEmployees();
				baseContent.setContent(contentEmployees);
			}
		});
		employees.setBackground(new Color(250, 250, 198));
		employees.setBorderPainted(false);
		employees.setFocusable(false);
		add(employees);
                    
		clients.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				setColorButton((JButton) e.getSource());
				contentClients = new ContentClients();
				baseContent.setContent(contentClients);
			}
		});
		clients.setBackground(new Color(250, 250, 198));
		clients.setBorderPainted(false);
		clients.setFocusable(false);
		add(clients);

		report.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				setColorButton((JButton) e.getSource());
				contentReport = new ContentReport();
				baseContent.setContent(contentReport);
			}
		});
		report.setBackground(new Color(250, 250, 198));
		report.setBorderPainted(false);
		report.setFocusable(false);
		add(report);

		logout.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		logout.setBackground(new Color(250, 250, 198));
		logout.setBorderPainted(false);
		logout.setHorizontalTextPosition(SwingConstants.LEFT);
		logout.setFocusable(false);
		add(logout);
	}

	private void setColorButton(JButton b) {
		record.setIcon(grayIcon);
		employees.setIcon(grayIcon);
		clients.setIcon(grayIcon);
		report.setIcon(grayIcon);
		record.setForeground(Color.GRAY);
		employees.setForeground(Color.GRAY);
		clients.setForeground(Color.GRAY);
		report.setForeground(Color.GRAY);
		b.setIcon(redIcon);
		b.setForeground(Color.BLACK);
	}
}
